package com.kotiln.lgc.sunnyweather.ui.place

import android.view.animation.Transformation
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.ViewModel
import com.kotiln.lgc.sunnyweather.logic.dao.Repository
import com.kotiln.lgc.sunnyweather.logic.model.Place

/**
 *@fileName PlaceViewModel
 *@date2020/11/27  13:54
 *@author PlaceViewModel$
 *@describe TODO
 *@desc
 */
class PlaceViewModel : ViewModel() {
    private val searchLiveData = MutableLiveData<String>()
    val placeList = ArrayList<Place>()
    val placeLiveData = Transformations.switchMap(searchLiveData) { query ->
        Repository.searchPlaces(query)
    }


    fun searchPlaces(query: String) {
        searchLiveData.value = query
    }

    fun savePlace(place:Place)=Repository.savePlace(place)
    fun getSavedPlace()=Repository.getSavedPlace()
    fun isPlaceSaved()=Repository.isPlaceSaved()
}